package com.x.servlet;

import com.x.bean.Achievement;
import com.x.bean.User;
import com.x.service.user.UserService;
import com.x.service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AchievementUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String code = req.getParameter("code");
        String courseName = req.getParameter("courseName");
        String score = req.getParameter("score");
        Achievement achievement = new Achievement();
        achievement.setCode(code);
        achievement.setCourseName(courseName);
        achievement.setScore(score);
        UserService userService = new UserServiceImpl();
        if (userService.updateAchievement(achievement)) {
            resp.sendRedirect(req.getContextPath()+"/jsp/frameAdmin.jsp");
        } else {
            req.setAttribute("error","修改失败");
            req.getRequestDispatcher("achievementUpdate.jsp").forward(req, resp);
        }
    }
}
